# """ 角色对象操作方法包
# @Project: Rebar
# @File: role_mapper.py
# @Author: hzc
# @Date: 2023/3/23 10:59
# """
# from sqlalchemy.exc import IntegrityError
# from typing import List
# from model.db import TbUserRole, rebar
# from model.params import RoleInfoParam
# from utils import DataNotExist
#
#
# def get_role(role_id: int) -> TbUserRole:
#     """
#     获取单个角色信息
#     :param role_id:
#     :return:
#     """
#     role = rebar.query(TbUserRole).filter(TbUserRole.role_id == role_id).first()
#     if not role:
#         raise DataNotExist("角色")
#     return role
#
#
# def get_roles() -> List[TbUserRole]:
#     """
#     获取角色列表
#     :return:
#     """
#     return rebar.query(TbUserRole).all()
#
#
# def add_role(role_info: RoleInfoParam) -> TbUserRole:
#     """
#     :param role_info:
#     :return:
#     """
#     try:
#         role = TbUserRole(
#             role_name=role_info.role_name,
#             role_rank=role_info.role_rank,
#             remark=role_info.remark
#         )
#         rebar.add(role)
#         rebar.commit()
#         rebar.refresh(role)
#         return role
#     except IntegrityError as e:
#         print("role_params.py", e, e.__traceback__.tb_lineno, sep="\n")
#         rebar.rollback()
#         raise e
#
#
# def delete_role(role_id: int) -> bool:
#     """
#     删除角色
#     :param role_id:
#     :return:
#     """
#     role = rebar.query(TbUserRole).filter(TbUserRole.role_id == role_id).first()
#     if not role:
#         raise DataNotExist("角色")
#     try:
#         rebar.delete(role)
#         rebar.commit()
#         rebar.refresh(role)
#         return True
#     except Exception as e:
#         print("role_params.py", e, e.__traceback__.tb_lineno)
#         rebar.rollback()
#         raise e
#
#
# def update_role(role_id: int, role_info: RoleInfoParam) -> TbUserRole:
#     """
#     更新role信息
#     :param role_id:
#     :param role_info:
#     :return:
#     """
#     role = rebar.query(TbUserRole).filter(TbUserRole.role_id == role_id).first()
#     if not role:
#         raise DataNotExist("角色")
#     try:
#         role.role_name = role_info.role_name
#         role.remark = role_info.remark
#         rebar.commit()
#         rebar.flush(role)
#         return role
#     except Exception as e:
#         print("role_params.py", e, e.__traceback__.tb_lineno)
#         rebar.rollback()
#         raise e
#
#
# def get_role_by_name(role_name) -> TbUserRole:
#     """
#     通过role_name获取role
#     :param role_name:
#     :return:
#     """
#     role = rebar.query(TbUserRole).filter(TbUserRole.role_name == role_name).first()
#     if not role:
#         raise DataNotExist("角色")
#     return role
#
#
#

